//
//  MyNavigationViewController.m
//  SquashSpark
//
//  Created by Coollang on 2017/10/26.
//  Copyright © 2017年 Coollang-YF. All rights reserved.
//

#import "MyNavigationViewController.h"
#import "UIImage+YFExtension.h"

@interface MyNavigationViewController ()

@end

@implementation MyNavigationViewController

+ (void)initialize {
    // 判断如果是当前的类(非子类)，才调用方法
    if (self == [MyNavigationViewController class]) {
        [self customizeAppearance];
    }
}

- (UIView *)maskView {
    if (_maskView == nil) {
        _maskView = [[UIView alloc] init];
        _maskView.backgroundColor = kMaskViewBgColor;
        _maskView.hidden = YES;
        [self.view addSubview:_maskView];
        [_maskView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.view);
        }];
    }
    return _maskView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
+ (void)customizeAppearance
{
    CGFloat textFont = 22.0f;
    UIFont *titleFont = [UIFont openSansFont:OpenSansBoldItalic size:textFont];
    
    NSDictionary *attr = @{NSForegroundColorAttributeName:kYellowGreenColor,NSFontAttributeName:titleFont};
    UINavigationBar *bar = [UINavigationBar appearance];
    bar.titleTextAttributes = attr;
    // 设置导航栏上的按钮的样式和颜色，如返回按钮
    bar.tintColor = kYellowGreenColor;
    [bar setBarTintColor:kNavBgThemeColor];
    bar.backgroundColor = kNavBgThemeColor;
    [[UINavigationBar appearance] setTranslucent:NO];
    [bar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    // 设置分割线
    [bar setShadowImage:[UIImage imageNamed:@"nav_separationLine"]];
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    [item setTitleTextAttributes:attr forState:UIControlStateNormal];
    NSDictionary *attrDis = @{NSForegroundColorAttributeName:[UIColor lightTextColor],NSFontAttributeName:[UIFont systemFontOfSize:16]};
    [item setTitleTextAttributes:attrDis forState:UIControlStateDisabled];
}
- (void)setHiddenSeparationLine:(BOOL)hiddenSeparationLine {
    _hiddenSeparationLine = hiddenSeparationLine;
    
    if (hiddenSeparationLine) {
        [self.navigationBar setShadowImage:[UIImage new]];
    }else {
        [self.navigationBar setShadowImage:[UIImage imageNamed:@"nav_separationLine"]];
    }
}



- (void)updateThemeUI
{
    self.view.backgroundColor = [UIColor colorWithHex:0xf7f7f7 alpha:1.0];
    [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_icon_background"] forBarMetrics:UIBarMetricsDefault];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    [viewController hidesBottomBarWhenPushed];
    [viewController setBaseBackBarItem];
    [super pushViewController:viewController animated:animated];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
    return UIStatusBarAnimationSlide;
}
- (BOOL)prefersStatusBarHidden {
    return NO;
}
#pragma mark - 控制屏幕旋转方法
- (BOOL)shouldAutorotate{
    return [[self.viewControllers lastObject] shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end
